<template>
  <div>
    <input type="text" class="username" placeholder="请输入用户名/邮箱" v-model="username">
    <input type="text" class="userpwd" placeholder="请输入密码" v-model="userpwd">
    <p class="tip" v-show="flag">用户名或者密码错误</p>
    <div class="login" @click="login">立即登录</div>
    <div class="login_other">其他方式登录</div>
    <div class="login_link">
      <a href="#/mine/reg">账号注册</a>
      <span>|</span>
      <a href="#">忘记密码</a>
    </div>
  </div>
</template>

<script>
import userinfosModel from "../../model/userinfosModel.js";
export default {
  data() {
    return {
      flag: false,
      username: "",
      userpwd: ""
    };
  },
  watch: {
    username() {
      this.flag = false;
    }
  },
  methods: {
    async login() {
      let { data: list } = await userinfosModel.query({
        username: this.username,
        userpwd: this.userpwd
      });
      if (list.length) {
        //登录去首页
        let username = list[0];
        localStorage.setItem("username", JSON.stringify(username));
        this.$router.push("/");
        console.log(6666);
      } else {
        this.flag = true;
      }
    }
  }
};
</script>


<style scoped>
.username,
.userpwd {
  width: 100%;
  line-height: normal;
  font-size: 14px;
  margin: 20px 0;
  background: 0;
  border: 1px solid gray;
  outline: 0;
  color: #333;
  margin-bottom: 0;
  border-radius: 0;
  height: 40px;
  padding: 5px 10px;
  box-sizing: border-box;
}
.tip {
  color: red;
  font-size: 12px;
}
.login {
  width: 100%;
  height: 40px;
  margin-top: 40px;
  margin-bottom: 40px;
  text-align: center;
  line-height: 40px;
  background-color: black;
  color: white;
}
.login_other {
  font-size: 12px;
  color: #666;
  text-align: center;
  margin-bottom: 30px;
}
.login_link {
  text-align: center;
}
.login_link a {
  display: inline-block;
  padding: 0 9px;
  font-size: 14px;
  color: #757575;
}
</style>
